import { ref, computed, reactive } from "vue";
import { defineStore } from "pinia";
import aApi from '@/api/Thirdparty'

export const dataStore = defineStore("dataall", () => {
	const activities = reactive([]) as any
	const label = reactive([]) as any
	const sort = reactive([]) as any
	const dynamic = reactive([]) as any
	const sortd = reactive([]) as any
	const formateDate = (datetime: any) => { //时间转换
		// let  = "2019-11-06T16:00:00.000Z"
		function addDateZero(num: any) {
			return (num < 10 ? "0" + num : num);
		}
		//   let datetime=account.info[0].u_birthday
		let d = new Date(datetime);
		//   let formatdatetime = d.getFullYear() + '-' + addDateZero(d.getMonth() + 1) + '-' + addDateZero(d.getDate());
		// //如果有时分秒就替换这个
		let formatdatetime = d.getFullYear() + '-' + addDateZero(d.getMonth() + 1) + '-' + addDateZero(d.getDate()) + ' ' + addDateZero(d.getHours()) + ':' + addDateZero(d.getMinutes()) + ':' + addDateZero(d.getSeconds());
		return formatdatetime;
	}
	const randomRgb = () => {
		let R = Math.floor(Math.random() * 255);
		let G = Math.floor(Math.random() * 255);
		let B = Math.floor(Math.random() * 255);
		return { background: 'rgb(' + R + ',' + G + ',' + B + ')' }
	}
	const colorRgb = () => {
		let R = Math.floor(Math.random() * 255);
		let G = Math.floor(Math.random() * 255);
		let B = Math.floor(Math.random() * 255);
		return { color: 'rgb(' + R + ',' + G + ',' + B + ')' }
	}
	const SeeData = reactive({       //查看动态变量
		a_id: null,
		u_id: null,
		a_title: '',
		a_views: '',
		a_comment_count: '',
		a_date: '',
		a_like_count: '',
		ds_id: '',
		a_content: '',
		a_cover: '',
		dl_id: [],
		a_abstract: '',
	})
	const avatarimg = reactive({ img: '' })
	function increment() {
		aApi.UomgAPI([]).then((res: any) => {
			avatarimg.img = res.data.imgurl

		}).catch(err => {
			console.log(err);
		})
		return avatarimg.img
	}
	//浏览器信息
	function BrowserInfo() {

		const BrowserInfo = reactive({
			platform: navigator.platform,
			appVersion: navigator.appVersion,
			userAgent: navigator.userAgent,
			osName: '',         // 操作系统名称
		})
		const deviceReg = reactive({
			data: [
				'Windows',
				'Mac',
				'iPhone',
				'iPad',
				'Android',
			]
		}) as any
		for (let i = 0; i < deviceReg.data.length; i++) {
			let patt1 = new RegExp(deviceReg.data[i]);
			if (patt1.test(BrowserInfo.userAgent)) {
				BrowserInfo.osName = deviceReg.data[i]
			}
		}
		return BrowserInfo;
	}
	const hometag = reactive({
		dl_name:[],
		dl_count:[],
	})
	const homesort = reactive({
		data:[],
	})
	return { activities, label, sort, dynamic, sortd, formateDate, colorRgb, randomRgb, SeeData, avatarimg, increment, BrowserInfo,hometag,homesort };
});
